package config

import (
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

func GormConfig(config Postgres) gorm.Config {
	return gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
			TablePrefix: config.Schema+".",
		},
		DisableForeignKeyConstraintWhenMigrating: true,
	}
}


func PostgresConfig(config Postgres) postgres.Config {
	dsn := "host=" + config.Host + " user="+ config.User+" password="+ config.Password+" dbname="+config.Database+
	" port="+config.Port+" sslmode=disable TimeZone=Asia/Shanghai"
	return postgres.Config{
		DSN:dsn,
		PreferSimpleProtocol: true,
	}
}